/**
 * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package doan.quanlycanbo.portlet.service.impl;

import java.util.List;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.ResourceConstants;

import doan.quanlycanbo.portlet.NoSuchdienbienhocviException;
import doan.quanlycanbo.portlet.model.dienbienhocvi;
import doan.quanlycanbo.portlet.service.base.dienbienhocviLocalServiceBaseImpl;

/**
 * The implementation of the dienbienhocvi local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link doan.quanlycanbo.portlet.service.dienbienhocviLocalService} interface.
 * </p>
 *
 * <p>
 * Never reference this interface directly. Always use {@link doan.quanlycanbo.portlet.service.dienbienhocviLocalServiceUtil} to access the dienbienhocvi local service.
 * </p>
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author Nguyen Tuan Vinh
 * @see doan.quanlycanbo.portlet.service.base.dienbienhocviLocalServiceBaseImpl
 * @see doan.quanlycanbo.portlet.service.dienbienhocviLocalServiceUtil
 */
public class dienbienhocviLocalServiceImpl
	extends dienbienhocviLocalServiceBaseImpl {
	
		public dienbienhocvi getByPrimaryKey(long madbhv) throws NoSuchdienbienhocviException, SystemException{
			return dienbienhocviPersistence.findByPrimaryKey(madbhv);
		}
	
		public List<dienbienhocvi> getAll() throws SystemException{
			return dienbienhocviPersistence.findAll();
		}
	
		public List<dienbienhocvi> getByHoso(long mahoso) throws SystemException{
			return dienbienhocviPersistence.findByHoSo(mahoso);
		}
		
		public List<dienbienhocvi> getByHocvi(long mahocvi) throws SystemException{
			return dienbienhocviPersistence.findByHocVi(mahocvi);
		}
	
		public dienbienhocvi addDBHV(dienbienhocvi dbhv1, long userId) throws SystemException{
			long madbhv = CounterLocalServiceUtil.increment(dienbienhocvi.class.getName());
			dienbienhocvi dbhv2 = dienbienhocviPersistence.create(madbhv);
			dbhv2.setGroupId(dbhv1.getGroupId());
			dbhv2.setCompanyId(dbhv1.getCompanyId());
			dbhv2.setLanguageId(dbhv1.getLanguageId());
			dbhv2.setMahoso(dbhv1.getMahoso());
			dbhv2.setMahocvi(dbhv1.getMahocvi());
			dbhv2.setChuyennganh(dbhv1.getChuyennganh());
			dbhv2.setNamphong(dbhv1.getNamphong());
			
			try {
				resourceLocalService.addResources(dbhv1.getCompanyId(), dbhv1.getGroupId(), userId, 
						dienbienhocvi.class.getName(), dbhv2.getPrimaryKey(), false, true, true);
			} catch (PortalException e) {
				e.printStackTrace();
			}
			
			return dienbienhocviPersistence.update(dbhv2, false);
		}
		
		public dienbienhocvi updateDBHV(long madbhv, long mahocvi, String chuyennganh, int namphong) throws NoSuchdienbienhocviException, SystemException{
			dienbienhocvi dbhv = dienbienhocviPersistence.findByPrimaryKey(madbhv);
			dbhv.setMahocvi(mahocvi);
			dbhv.setChuyennganh(chuyennganh);
			dbhv.setNamphong(namphong);
			return dienbienhocviPersistence.update(dbhv, false);
		}
	
		public void deleteDBHV(long madbhv) throws SystemException, PortalException{
			dienbienhocvi dbhv = dienbienhocviPersistence.findByPrimaryKey(madbhv);
			deleteDBHV(dbhv);
		}
		
		public void deleteDBHV(dienbienhocvi dbhv) throws SystemException, PortalException{
			resourceLocalService.deleteResource(dbhv.getCompanyId(), dienbienhocvi.class.getName(), ResourceConstants.SCOPE_INDIVIDUAL, dbhv.getPrimaryKey());
			dienbienhocviPersistence.remove(dbhv);
		}
}




